package top.boycharse.blog.bean.Response;

public class BaseResponse<T> {

    private int code;

    private String msg;

    private T data;

    public BaseResponse() {

    }

    public BaseResponse(T data) {
        this.code = ResponseCode.CODE_SUCCESS;
        this.msg = ResponseMsg.MSG_SUCCESS;
        this.data = data;
    }

    public BaseResponse(String msg, T data) {
        this.code = ResponseCode.CODE_SUCCESS;
        this.msg = msg;
        this.data = data;
    }

    public BaseResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static BaseResponse<String> buildSuccessMsg(String msg) {
        return new BaseResponse<>(ResponseCode.CODE_SUCCESS,msg,null);
    }

    public static BaseResponse<String> buildFailMsg(int code, String msg) {
        return new BaseResponse<>(code, msg,null);
    }

    /**
     * 没有登录
     * @return BaseResponse
     */
    public static BaseResponse<String> buildNotLogin() {
        return buildFailMsg(ResponseCode.CODE_NOT_LOGIN,ResponseMsg.MSG_NOT_LOGIN);
    }

    /**
     * 登录成功
     * @return BaseResponse
     */
    public static BaseResponse<String> buildSuccessLogin() {
        return new BaseResponse<>(ResponseMsg.MSG_SUCCESS_LOGIN);
    }

    /**
     * 登录失败
     * @return BaseResponse
     */
    public static BaseResponse<String> buildFailLogin() {
        return buildFailMsg(ResponseCode.CODE_NOT_USER,ResponseMsg.MSG_NOT_USER);
    }

    /**
     * 没有操作权限
     * @return BaseResponse
     */
    public static BaseResponse<String> buildNotPermission() {
        return buildFailMsg(ResponseCode.CODE_NOT_PERMISSION,ResponseMsg.MSG_NOT_PERMISSION);
    }

    /**
     * 参数异常
     * @return BaseResponse
     */
    public static BaseResponse<String> buildParamException() {
        return buildFailMsg(ResponseCode.CODE_PARAM_EXCEPTION,ResponseMsg.MSG_PARAM_EXCEPTION);
    }
}
